package com.company.demo.controller;

import com.company.demo.factory.StrategyFactory;
import com.company.demo.pojo.WxBlance;
import com.company.demo.pojo.WxTrade;
import com.company.demo.strategy.IDeduction;
import com.company.demo.strategy.StrategyEnum;


/**
 * 扣款调用类
 */
public class DeductionFacade {

    //扣款
    public static void deduct(WxBlance wxBlance, WxTrade wxTrade) {
        StrategyEnum strate = getStrate(wxBlance, wxTrade);
        IDeduction deduction = StrategyFactory.getDeduction(strate);
        deduction.exec(wxBlance,wxTrade);
    }

    //获取扣款策略
    private static  StrategyEnum getStrate(WxBlance wxBlance, WxTrade wxTrade) {
        if (wxBlance.getBlance().compareTo(wxTrade.getTradeAmout()) < 0) {
            return StrategyEnum.IdCardDeduction;
        }else {
            return StrategyEnum.BlanceDeduction;
        }
    }
}
